package com.tang.oss.config;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.tang.oss.adapter.AliStorageAdapter;
import com.tang.oss.adapter.MinioStorageAdapter;
import com.tang.oss.adapter.StorageAdapter;
import com.tang.oss.enums.StorageAdapterEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@RefreshScope
public class StorageConfig {
    @Value(value = "${storage.service.type}")
    private String storageType;

    @Bean
    @RefreshScope
    public StorageAdapter storageAdapter() {
        if (storageType.equals(StorageAdapterEnum.ALI_OSS.type)) {
            return new AliStorageAdapter();
        } else if (storageType.equals(StorageAdapterEnum.MINIO.type)) {
            return new MinioStorageAdapter();
        }
        throw new IllegalArgumentException("未找到对应的文件适配器");
    }
}
